const router = require("koa-router")()
const {
  getHotList,
  getShopInfo,
  getProductByShopId
} = require("../controller/shop")
const { SuccessModel, ErrorModel } = require("../res-module/index")

router.prefix("/api/shop")

// 获取商店列表
router.get("/hot-list", async function (ctx, next) {
  const list = await getHotList()
  ctx.body = new SuccessModel(list)
})
// 商店详情
router.get("/:id", async function (ctx, next) {
  const id = ctx.params.id
  const shop = await getShopInfo(id)
  ctx.body = new SuccessModel(shop)
})
// 根据商店获取商品
router.get("/:id/products", async function (ctx, next) {
  const shopId = ctx.params.id
  const tab = ctx.query.tab || "all"
  const product = await getProductByShopId(shopId, tab)
  ctx.body = new SuccessModel(product)
})

module.exports = router
